package com.twu.biblioteca;


import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

public class UserHelper {

    List<User> users = new LinkedList<User>();

    public UserHelper() {

        users.add(new User("111-1111", "password", "Tunji Sunmonu", "tunjisun@thoughtworks.com", "256-89020"));
        users.add(new User("111-1112", "password1", "Tim Akampa", "akampati@thoughtworks.com", "256-890230"));
    }

    public User getUser(String username) {

        for (Iterator i = users.iterator(); i.hasNext(); ) {
            User user = (User) i.next();
            if (user.getUserName().equals(username)) {
                return user;
            }
        }
        return null;
    }

    public boolean isUserCredetialsCorrect(String username, String password) {

        for (Iterator i = users.iterator(); i.hasNext(); ) {
            User user = (User) i.next();
            if (user.getUserName().equals(username) && user.getPassword().equals(password)) {
                return true;
            }
        }
        return false;
    }

    public String[] getUserCredentials() {

        StringFormatter stringFormatter = new StringFormatter();
        String[] userCredentials = new String[2];

        userCredentials[0] = stringFormatter.getUserInput("Enter Username : ");
        userCredentials[1] = stringFormatter.getUserInput("Enter Password : ");

        return userCredentials;

    }
}
